package net.youball.action;

import java.util.HashMap;
import java.util.Map;

import com.opensymphony.xwork2.ModelDriven;

import net.youball.entity.BallInnings;
import net.youball.service.IInningsService;
import net.youball.utils.String.Json;
import net.youball.utils.String.StringUtils;
import net.youball.utils.page.Args;
import net.youball.utils.page.PageBean;

public class InningsAction extends BaseAction implements ModelDriven<BallInnings>{

/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private IInningsService inningsService;
	
	 

	public String push(String args) {
		// TODO Auto-generated method stub
		Map<String,Object> map=Json.jsonToObject(args);
		BallInnings innings=new BallInnings();
		if(map!=null&&map.size()!=0){
			String name=map.get("name").toString();
			String detail=map.get("detail").toString();
			String type=map.get("type").toString() ;
			String wager=map.get("wager").toString();	
			String limit=map.get("limit").toString();
			String ball=map.get("ball").toString();
			String time=map.get("time").toString();
			String addr=map.get("addr").toString();
			String free=map.get("free").toString();
			String location=map.get("location").toString();
			if(name!=null)
				innings.setInningsName(name);
			if(detail!=null)
				innings.setInningsDetail(detail);
			if(StringUtils.compareNumber(wager))
				innings.setInningsWagerId(Integer.parseInt(wager));
			if(StringUtils.compareNumber(type))
				innings.setInningsType(Integer.parseInt(type));
			if(StringUtils.compareNumber(limit))
				innings.setInningsLimit(Integer.parseInt(limit));
			if(StringUtils.compareNumber(ball))
				innings.setInningsBallCarryUserId(Integer.parseInt(ball));
			if(StringUtils.compareTrim(time))
				innings.setInningsTime(Long.parseLong(time));
			if(StringUtils.compareTrim(addr))
				innings.setInningsAddr(addr);
			if(StringUtils.compareNumber(free))
				innings.setInningsFree(Integer.parseInt(free));
			if(StringUtils.compareTrim(location))
				innings.setInningsLocation(location);
			
			inningsService.add(innings);
			
		}
		return null;
	}
	
	public String getNear(){
		PageBean p=new PageBean();
		Map<String, Args> map=new HashMap<String, Args>();
		String name=request.getParameter("name");
		Args a=new Args();
		a.setComp("like");
		a.setValue(a);
		map.put("InningsName", a);
		p.setBegin(0);
		p.setCount(10);
		p.setArgs(map);
		inningsService.findByPage(p);
		String json=Json.objectToStr(p.getData());
		this.outJson(json);
		return null;
	}
	
	public IInningsService getInningsService() {
		return inningsService;
	}


	public void setInningsService(IInningsService inningsService) {
		this.inningsService = inningsService;
	}


	public BallInnings getModel() {
		// TODO Auto-generated method stub
		return null;
	}
	
	
}
